package com.zhang.ifelse;

import java.util.HashMap;
import java.util.Map;
public class Test16 {
	/**
	 * java265.com 示例程序 数组转集合
	 * 
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {


		PaySort paySort = PayFactory.getPaySortService("微信");
		if (null != paySort) {
			paySort.pay();
		}

		PaySort paySort1 = PayFactory.getPaySortService("信");
		if (null != paySort1) {
			paySort1.pay();
		}

		PaySort paySort2 = PayFactory.getPaySortService("银行卡");
		if (null != paySort2) {
			paySort2.pay();
		}
	}
}


abstract class PaySort {

	protected void pay() {
		throw new UnsupportedOperationException("无可用的支付方式");
	}
}

class WeixinPay extends PaySort {

	@Override
    public void	pay(){
		System.out.println("我是微信支付！");
	}

}

class BankCardPay extends PaySort {
	@Override
	public void pay() {
		System.out.println("我是银行卡支付！");
	}
}


class PayFactory{
	
	static Map<String, PaySort> map = new HashMap<>();
	
	static {
		map.put("微信", new WeixinPay());
		map.put("银行卡", new BankCardPay());
	}

	public static PaySort getPaySortService(String payName) {
		return map.get(payName);
	}

}